const { _update } = require('../controller/index.js');
const {query} = require('../utils/mysql.js')

module.exports={
    // 登录的sql语句
    async _loginServer ({username,password}){
        const sql = ` select * from cms_user where username =? and password = ? `
        return await query(sql,[username,password])
    },
    // 获取用户名的sql语句
    async _getUsernameServer(username){
        console.log(username,'serverusername');
        const sql = ` select * from cms_user  where username =? `
        return await query(sql,[username])
    },
    // 修改用户密码的sql语句
    async _updatePasswordServer({username,password}){
        const sql = ` update cms_user set password = ?  where username = ? `
        return await query(sql,[password,username])
    },
    // 获取数据列表的sql语句
    async _getlistlength(){
        const sql = ` select * from cms_student `
        return await query(sql)
    },
    // 根据page,size获取分页后的sql语句
    async _getlistServer({page,size}){
        let start = (page - 1) * size
        const sql = ` select * from  cms_student  limit ${start} , ${size} `
        return await query(sql)
    },
    //   根据id删除数据的sql语句
    async _deleteServer({id}){
        console.log(id,'ididid');
        const sql = ` delete from  cms_student  where stuNo = ? `
        return await query(sql,[id])
    }, 
    // 根据id修改的sql语句
    async _editServer({stuNo,stuName,status,salary,workCity,collegeId,expertiseId,origin,className,createdTime,lastModTime,archived,gradYear,id}){
        const sql = ` update  cms_student set stuNo = ? ,stuName = ? ,status = ?,salary = ?,workCity=?,collegeId=?,expertiseId=?,
        origin=?,className=?,createdTime=?,lastModTime=?,archived=?,gradYear=?
        where id = ? `
        return await query(sql,[stuNo,stuName,status,salary,workCity,collegeId,expertiseId,origin,className,createdTime,lastModTime,archived,gradYear,id])
    },
    // 新增数据的sql语句
    async _addServer({stuNo,stuName,status,salary,workCity,collegeId,expertiseId,origin,className,createdTime,lastModTime,archived,gradYear}){
        console.log(lastModTime,'lastModTimelastModTime');
        const sql = `insert into cms_student (stuNo,stuName,status,salary,workCity,collegeId,expertiseId,origin,className,createdTime,lastModTime,archived,gradYear) values (?,?,?,?,?,?,?,?,?,?,?,?,?);`
        return await query(sql,[stuNo,stuName,status,salary,workCity,collegeId,expertiseId,origin,className,createdTime,lastModTime,archived,gradYear])
    },
    // 批量删除
    async _batchdeletionServer({ids}){
        console.log(ids,'idsidsids');   
        const sql = `delete from cms_student where id in (${ids})`
        return await query(sql)
    },
    // 查询的sql语句
    async _SelectServer(name,market,scholl,address){
        let sql = ` select * from  cms_student  where 1 = 1 `
        let conditions = [];  
        if (name !== '') {  
            conditions.push(`stuName = '${name}'`);  
        }
        if (market !== '') {  
        conditions.push(`origin = '${market}'`);  
        }  
        if (scholl !== '') { // 修正变量名为 school  
        conditions.push(`collegeId = '${scholl}'`);  
        }  
        if (address !== '') {  
        conditions.push(`workCity = '${address}'`);  
        }  
        if (conditions.length > 0) {  
        sql += ` and ${conditions.join(' and ')}`;      
        }  
        console.log(sql,'sqlsqlsql');
        return await query(sql)
    }
}